<template>
  <div style="width: 100%">
    <a-card class="card" :bordered="false" >
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:24}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="招生学年">
              <a-select :allowClear="true" showSearch optionFilterProp="children"  v-model="queryParam.zsxn">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:16}" :xl="{span:8}">
            <a-button type="primary" @click="loadData" style="margin-top:29px">查询</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
  </a-card >   
    <a-card :bordered="false">
      <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :pagination="pagination"
      @change="handleTableChange"
    >

      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
    </a-card>
  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import G2 from '@antv/g2'
const selectArr = ['TYPE0126']

export default {
  name: 'Online',
  components: {
    STable
  },
  data () {
    return {
      loading: false,
      queryParam:{
        zsxn:''
      },
      pagination:{

      },
      data: [],
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '院系代码',
          dataIndex: 'lqyxm'
        },
        {
          title: '院系',
          dataIndex: 'lqyxmc'
        },
        {
          title: '专业代码',
          dataIndex: 'lqzym'
        },
        {
          title: '专业名称',
          dataIndex: 'lqzymc'
        },
        {
          title: '报名人数',
          dataIndex: 'bmrs'
        },
        {
          title: '上线人数(不包括推免生)',
          dataIndex: 'sxrs'
        },
        {
          title: '推免人数',
          dataIndex: 'tmrs'
        }
      ]
    }
  },
    computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
    this.loadData()
  },
  methods: {
    // 加载数据
    loadData(parameter = {}) {
      if(!parameter.pageNum){
        this.pagination.current = 1
        parameter.pageNum = 1
        parameter.pageSize = 10
      }
      if(!this.queryParam.zsxn)this.queryParam.zsxn = ''
      this.loading = true;
      var parmas = Object.assign(parameter,this.queryParam)
      this.$api.situation.onlineList(parmas).then(res => {
        // console.log(res)
         const pagination = { ...this.pagination
        };
        pagination.total = 0
        if (res.data && res.data.total) {
          pagination.total = res.data.total;
        }
        this.data = []
         if (res.data && res.data.rows.length) {
           this.data = res.data.rows
         }
        this.pagination = pagination;
        this.loading = false;
      })
    },
        // 分页
    handleTableChange(pagination, filters, sorter) {
      console.log(pagination);
      const pager = { ...this.pagination
      };
      pager.current = pagination.current;
      this.pagination = pager;
      this.loadData({
        pageSize: 10,
        pageNum: pagination.current
      });
    },
  }
}
</script>
<style lang='less' scoped>
.card{
  margin-bottom: 20px;
}
</style>